package cnsatmsmart.automation.mmi.model.data.TSafe;

/**
 * @author SIK - PTIK, BPPT
 **/

public class FlightPlan {   //based on TSafe
    /* const */
        public static final String FIXES_SEPARATOR_SINGLE = ".";
        public static final String FIXES_SEPARATOR_DOUBLE = "..";
        public static final String FACILITY_CODE = "FACILITY_CODE";
        public static final String FP_MESSAGE_TYPE = "FZ";
        public static final String AMEND_FP_MESSAGE_TYPE = "AF";

        public static final int AMEND_SPEED = 1;
        public static final int AMEND_ALTITUDE = 16;
        public static final int AMEND_ROUTE = 256;

    /* atribut - atribut yang dimiliki oleh kelas FlightPlan */
        private double speed;       //kecepatan pesawat
        private double altitude;    //ketinggian pesawat
        private Route route;        //rute pesawat
        private long lastUpdate;    //waktu terakhir dilakukan update terhadap jadwal pesawat
        private String key;

    /* constructor - user defined ctor, no default ctor */
        // <editor-fold defaultstate="collapsed" desc="ctor">
        /*
         * @param = atribut
         */
        public FlightPlan (double speed, double altitude, Route route) {
            if (route == null) {
                throw  new NullPointerException("null route");
            } else {
                this.speed = speed;
                this.altitude = altitude;
                this.route = route;
                this.lastUpdate = System.currentTimeMillis();
                return;
            }
        }
        // </editor-fold>

    /* setter */
        public void setLastUpdate (long lastUpdate) {
            /* I.S. sebarang */
            /* F.S. this.lastUpdate terdefinisi dan bernilai sama dengan parameter lastUpdate */
            /* Proses : mengisikan dan mengubah nilai this.lastUpdate dengan parameter lastUpdate */
                this.lastUpdate = (lastUpdate == 0l ? System.currentTimeMillis() : lastUpdate);
        }
        public void setKeyString (String key) {
            /* I.S. sebarang */
            /* F.S. this.key terdefinisi dan bernilai sama dengan parameter key */
            /* Proses : mengisikan dan mengubah nilai this.key dengan parameter key */
                this.key = key;
        }

    /* getter */
        public double getAssignedSpeed () {
            /* mengembalikan nilai dari atribut speed */
            return (this.speed);
        }
        public double getAssignedAltitude () {
            /* mengembalikan nilai dari atribut altitude */
            return (this.altitude);
        }
        public Route getRoute () {
            /* mengembalikan nilai dari atribut route */
            return (this.route);
        }
        public long getLastUpdate () {
            /* mengembalikan nilai dari atribut lastUpdate */
            return (this.lastUpdate);
        }
        public String getKeyString () {
            /* mengembalikan nilai dari atribut key */
            return (this.key);
        }

    /* method - method yang dimiliki oleh kelas FlightPlan */
        public FlightPlan amendAssignedSpeed (double newSpeed) {
            this.lastUpdate = System.currentTimeMillis();
            return (new FlightPlan(newSpeed, this.altitude, this.route));
        }
        public FlightPlan amendAssignedAltitude (double newAltitude) {
            this.lastUpdate = System.currentTimeMillis();
            return (new FlightPlan(this.speed, newAltitude, this.route));
        }
        public FlightPlan amendRoute (Route newRoute) {
            this.lastUpdate = System.currentTimeMillis();
            return (new FlightPlan(this.speed, this.altitude, new Route(newRoute)));
        }

    public int compareTo (double speed, double altitude, String route) {
        int RetVal = 0;
        if (this.speed != speed) {
            RetVal |= 1;
        }
        if (this.altitude != altitude) {
            RetVal |= 0x10;
        }
        if ((this.key != null) && (route != null) && (this.key.compareTo(route) != 0)) {
            RetVal |= 0x100;
        }

        return (RetVal);
    }
}
